<%-- 
    Document   : index
    Created on : 17.11.2011, 1:04:27
    Author     : Дима
--%>

<%@page import="java.util.LinkedList"%>
<%@page import="java.util.List"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Iterator"%>
<%@page import="encaps.entities.Comment"%>
<%@page import="java.util.Date"%>
<%@page import="javax.ejb.CreateException"%>
<%@page import="javax.naming.NamingException"%>
<%@page import="encaps.entities.MovieLocal"%>
<%@page import="encaps.entities.MovieLocalHome"%>
<%@page import="java.util.Collection"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.naming.Context"%>
<%@page contentType="text/html" pageEncoding="UTF-8" errorPage="error.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>  <%
        MovieLocalHome mHome = null;
        MovieLocal p = null;
        String cs="monster.jpg";
        Collection col;
        HashMap coms;
        try {
            Context ctx = new InitialContext();
            mHome = (MovieLocalHome) ctx.lookup("java:comp/env/ejb/Movie");
            //HashSet genres = new HashSet(); genres.add("fantasy");
//            p = mHome.create("mov1", "PIC1","DESCRIPT1111111111", genres);
        p = mHome.findByPrimaryKey(new Long(1));
        coms = p.getComments();
        if (coms.isEmpty()) {
            col = new LinkedList();
            col.add(new Comment(new Long(0), new Long(0),"NO COMMENTS", new Date()));
        } else {
            col= coms.values();
        }
//        p.setPicture(cs);
        } catch(NamingException e) {
              throw new ServletException("Error looking up home", e);
        } 
//    } catch(CreateException e) {
//      throw new ServletException("Error creating local hello bean", e);
    
         %>
        <h1>Hello World!</h1>   
               val: <%= ((MovieLocal)p).stringRepresentation() %>
       <br>
              value: <%
        Iterator ic = col.iterator();
        Comment coment;
        while (ic.hasNext()) {
            coment = (Comment)ic.next(); %>
        <%= coment.stringRepresentation()%>
        <br>   <%
} %>  
        <br>   
    </body>
</html>
